package com.demo.controller;

import com.demo.model.Student;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;

/**
 * @author vivi
 * @description
 * @date 2024/5/21
 */
@Controller
public class StudentController {

//    // 1 使用属性注入的方法获取Bean
////    @Autowired //自动写入
//    @Resource
//    private StudentService studentService;
//
//
////    // 2 set注入
////    private StudentService studentService;
////    @Autowired
////    public void setStudentService (StudentService studentService) {
////        this.studentService = studentService;
////    }
//
////    // 3 构造方法注入
////    // 当有多个构造方法时， 必须加 @Autowired
////    private StudentService studentService;
////
////    @Autowired
////    public StudentController (StudentService studentService) {
////        this.studentService = studentService;
////    }
//
//    public void show() {
//        //调用service方法
//        studentService.show();
//
//    }
//    @Resource(name = "student2")
    @Autowired
    @Qualifier("student2")  // 注解定义名称
    private Student student;

    public void show() {
        System.out.println(student.toString());
    }

}

















